<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Design Pattern</title>
    <meta name="language" content="en" />
    <!--myInjectedScript-->
</head>
<body>
    <h1>
        Factory Method</h1>
    <div class="section">
        <h2>
            Intent</h2>
        <p>
            Define an interface for creating an object, but let subclasses decide which class
            to instantiate. Factory Method lets a class defer instantiation to subclasses.
            <br />
            
        </p>
    </div>
    <div class="section">
        <h2>
            Also known as</h2>
        <p>
            Virtual Constructor</p>
        <h2>
            Motivation</h2>
        <p>
            Frameworks use abstract classes to define and maintain relationships between objects.
            A framework is often responsible for creating these objects as well.
            <br />
            <a href="http://en.wikipedia.org/wiki/Factory_method_pattern" target="_blank">Online
                resources</a>
        </p>
    </div>
    <div class="section">
        <h2>
            Applicability</h2>
        <p>
            <ol>
                <li>a class can't anticipate the class of objects it must create.</li>
                <li>a class wants its subclasses to specify the objects it creates.</li>
                <li>classes delegate responsibility to one of several helper subclasses, and you want
                    to localize the knowledge of which helper subclass is the delegate.</li>
            </ol>
        </p>
    </div>
    <div class="section">
        <h2>
            Class Diagram</h2>
        <p>
            <img alt="Diagram" src=" factorymethod.png" border="0" />
        </p>
    </div>
    <div class="section">
        <h2>
            Collaborations</h2>
        <p>
            Creator relies on its subclasses to define the factory method so that it returns
            an instance of the appropriate ConcreteProduct.
            <br />
        </p>
        <h2>
            Consequences</h2>
        <p>
            <ol>
                <li>Factory methods eliminate the need to bind application-specific classes into your
                    code. The code only deals with the Product interface; therefore it can work with
                    any user-defined ConcreteProduct classes. </li>
                <li>Provides hooks for subclasses. Creating objects inside a class with a factory method
                    is always more flexible than creating an object directly. Factory Method gives subclasses
                    a hook for providing an extended version of an object.</li>
                <li>clients can find factory methods useful, especially in the case of parallel class
                    hierarchies. It localizes knowledge of which classes belong together.</li>
            </ol>
        </p>
    </div>
    <div class="section">
        <h2>
            Related Patterns</h2>
        <p>
            <ul>
                <li><a href="">Abstract Factory</a> is often implemented with factory methods. </li>
                <li>Factory methods are usually called within <a href="">Template Methods</a>. </li>
                <li><a href="">Prototypes</a> don't require subclassing Creator, but they often require an Initialize
                    operation on the Product class. Creator uses Initialize to initialize the object.
                    <a href="">Factory Method</a> doesn't require such an operation. </li>
            </ul>
        </p>
    </div>
</body>
</html>
